﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minesweeper
{
    class TimeDigits
    {
        private static readonly string block = ((char)0x2588).ToString();

        private static readonly string[] zeroDigit =
            {
               block + block + block,
               block + " " + block,
               block + " " + block,
               block + " " + block,
               block + block + block,
            };

        private static readonly string[] nineDigit =
            {
                block + block + block,
                block + " " + block,
                block + block + block,
                "  " + block,
                block + block + block,
            };

        private static readonly string[] oneDigit =
            {
                "  " + block,
                "  " + block,
                "  " + block,
                "  " + block,
                "  " + block,
            };

        private static readonly string[] twoDigit =
            {
                block + block + block,
                "  " + block,
                block + block + block,
                block + "  ",
                block + block + block,
            };

        private static readonly string[] threeDigit =
            {
                block + block + block,
                "  "+ block,
                block + block + block,
                "  " + block,
                block + block + block,
            };

        private static readonly string[] fourDigit =
            {
                block + " " + block,
                block + " " + block,
                block + block + block,
                "  " + block,
                "  " + block,
            };

        private static readonly string[] fiveDigit =
            {
                block + block + block,
                block + "  ",
                block + block + block,
                "  " + block,
                block + block + block,
            };

        private static readonly string[] sixDigit =
            {
                block + block + block,
                block + "  ",
                block + block + block,
                block + " " + block,
                block + block + block,
            };

        private static readonly string[] sevenDigit =
            {
                block + block + block,
                "  "+ block,
                "  "+ block,
                "  "+ block,
                "  "+ block,
            };

        private static readonly string[] eightDigit =
            {
                block + block + block,
                block + " "+ block,
                block + block + block,
                block + " "+ block,
                block + block + block,
            };

        public static void DrawTimeDigit(int positionX, int positionY, int digit)
        {
            var oldBgColor = Console.BackgroundColor;
            var oldFgColor = Console.ForegroundColor;
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Red;
            string[] toBeWritten = new string[5];
            switch (digit)
            {
                case 0:
                    Array.Copy(zeroDigit,toBeWritten,5);
                    break;
                case 1:
                    Array.Copy(oneDigit, toBeWritten, 5);
                    break;
                case 2:
                    Array.Copy(twoDigit, toBeWritten, 5);
                    break;
                case 3:
                    Array.Copy(threeDigit, toBeWritten, 5);
                    break;
                case 4:
                    Array.Copy(fourDigit, toBeWritten, 5);
                    break;
                case 5:
                    Array.Copy(fiveDigit, toBeWritten, 5);
                    break;
                case 6:
                    Array.Copy(sixDigit, toBeWritten, 5);
                    break;
                case 7:
                    Array.Copy(sevenDigit, toBeWritten, 5);
                    break;
                case 8:
                    Array.Copy(eightDigit, toBeWritten, 5);
                    break;
                case 9:
                    Array.Copy(nineDigit, toBeWritten, 5);
                    break;
            }
            for (int element = 0; element < toBeWritten.Length; element++)
            {
                Console.SetCursorPosition(positionX, positionY);
                Console.Write(toBeWritten[element]);
                positionY++;
            }

            Console.BackgroundColor = oldBgColor;
            Console.ForegroundColor = oldFgColor;
        }

        public static void DrawTimeBox(int posX, int posY)
        {
            var oldBgColor = Console.BackgroundColor;
            var oldFgColor = Console.ForegroundColor;

            string border = new string((char)0x2588, 25);
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.SetCursorPosition(posX, posY);
            Console.Write(border);
            string empty = new string(' ',21);
            for (int index = 0; index < 7; index++)
            {
                posY++;
                Console.SetCursorPosition(posX, posY);
                Console.Write(block +block + empty + block + block);
            }
            posY++;
            Console.SetCursorPosition(posX, posY);
            Console.Write(border);

            Console.BackgroundColor = oldBgColor;
            Console.ForegroundColor = oldFgColor;
        }
    }
}
